package com.itbuka.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itbuka.goods.domain.ProductDetails;
import com.itbuka.goods.mapper.ProductDetailsMapper;
import com.itbuka.goods.service.ProductDetailsService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author apple
* @description 针对表【goods_product_details(商品详情表)】的数据库操作Service实现
* @createDate 2024-07-30 16:15:41
*/
@Service
public class ProductDetailsServiceImpl implements ProductDetailsService {
@Autowired
private ProductDetailsMapper iProductDetailsMapper;

@Override
public List<ProductDetails> selectAll() {
LambdaQueryWrapper <ProductDetails> lqw = new LambdaQueryWrapper<>();
lqw.eq(ProductDetails::getIsDelete,0);
return iProductDetailsMapper.selectList(lqw);
}


@Override
public List<ProductDetails> selectList(ProductDetails iProductDetails) {
LambdaQueryWrapper <ProductDetails> lqw = this.lqw(iProductDetails);
return iProductDetailsMapper.selectList(lqw);
}

@Override
public Integer insert(ProductDetails iProductDetails) {
return iProductDetailsMapper.insert(iProductDetails);
}

@Override
@Transactional
public Integer delete(String ids) {
try {
String[] split = ids.split(",");
for (String id : split) {
ProductDetails iProductDetails = new ProductDetails();
iProductDetails.setId(Long.parseLong(id));
iProductDetails.setIsDelete(1);
iProductDetailsMapper.updateById(iProductDetails);
}
return 1;
}catch (Exception e){
return -1;
}
}

@Override
public Integer update(ProductDetails iProductDetails) {
return iProductDetailsMapper.updateById(iProductDetails);
}

@Override
public Page<ProductDetails> pageAll(Integer page, Integer size) {
PageHelper.startPage(page,size);
return (Page<ProductDetails>)this.selectAll();
}

@Override
public Page<ProductDetails> pageList(ProductDetails iProductDetails, Integer page, Integer size) {
PageHelper.startPage(page,size);
return (Page<ProductDetails>)this.selectList(iProductDetails);
}

public LambdaQueryWrapper lqw(ProductDetails iProductDetails){
LambdaQueryWrapper <ProductDetails> lqw = new LambdaQueryWrapper<>();
    if (iProductDetails.getId() != null){
    lqw.eq(ProductDetails::getId,iProductDetails.getId());
    }
    if (iProductDetails.getSpecId() != null){
    lqw.eq(ProductDetails::getSpecId,iProductDetails.getSpecId());
    }
    if (iProductDetails.getNum() != null){
    lqw.eq(ProductDetails::getNum,iProductDetails.getNum());
    }
    if (iProductDetails.getWeight() != null){
    lqw.eq(ProductDetails::getWeight,iProductDetails.getWeight());
    }
    if (iProductDetails.getPrice() != null){
    lqw.eq(ProductDetails::getPrice,iProductDetails.getPrice());
    }
    if (iProductDetails.getInventory() != null){
    lqw.eq(ProductDetails::getInventory,iProductDetails.getInventory());
    }
    if (iProductDetails.getImg() != null){
    lqw.eq(ProductDetails::getImg,iProductDetails.getImg());
    }
    if (iProductDetails.getProductId() != null){
    lqw.eq(ProductDetails::getProductId,iProductDetails.getProductId());
    }
    if (iProductDetails.getIsDelete() != null){
    lqw.eq(ProductDetails::getIsDelete,iProductDetails.getIsDelete());
    }
    if (iProductDetails.getCreateTime() != null){
    lqw.eq(ProductDetails::getCreateTime,iProductDetails.getCreateTime());
    }
    if (iProductDetails.getUpdateTime() != null){
    lqw.eq(ProductDetails::getUpdateTime,iProductDetails.getUpdateTime());
    }
return lqw;
}
}




